home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
4.1
/
Interface-Clocks.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
7KB
|
241 lines
" NAME Interface-Clocks
AUTHOR Bernard Horan <bernard@is.morgan.com>
CONTRIBUTOR Bernard Horan <bernard@is.morgan.com>
FUNCTION Clocks
ST-VERSIONS 4.1
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1.1
DATE September 1992
SUMMARY A category of clocks. Re-implementation (almost) of clocks from VI2.3 for new release. Bernard Horan, 25/9//92"!
View subclass: #ClockView
instanceVariableNames: 'myProject date '
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Clocks'!
ClockView comment:
' I''m an abstract superclass for clockViews. In true O-O fashion I am the result of
an abstraction of existing (VI2.3) classes -- see my subclasses.
Instance variables:
myProject <project> the project I''m open in and,
date <date> the date I have in my label
Bernard Horan
29 June 1992'!
!ClockView methodsFor: 'initialize'!
initialize
"set up the view's constants"
super initialize.
myProject := Project current.
date := Date today! !
!ClockView methodsFor: 'controller access'!
defaultControllerClass
^ClockController! !
!ClockView methodsFor: 'displaying'!
displayOn: aGraphicsContext
"called from the outside, check the date and update the time."
| today |
today := Date today.
date = today
ifFalse:
[date := today.
self topComponent newLabel: today].
self topComponent isCollapsed ifFalse: [self displayTimeOn: aGraphicsContext]! !
ClockView subclass: #AClockView
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Clocks'!
AClockView comment:
'I am the view of the ASCII clock - I display the date in my top component''s label and display the time in my insides.
Amended from the VI2.3 version.
Bernard Horan, 29 June 1992'!
!AClockView methodsFor: 'displaying'!
displayTimeOn: aGraphicsContext
"update the time in the view with now's string"
| str text |
str := Time now printString.
str := str copyFrom: 1 to: (str size - 6). "remove seconds"
(text := str asComposedText)
displayOn: aGraphicsContext
at: (self bounds center - text bounds center) "put up the string"! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
AClockView class
instanceVariableNames: ''!
AClockView class comment:
'I am the view of the ASCII clock - I hold the date in my label tab and display the time in my insides.
My instance variables are:
<myProject> the project i''m open in and,
<date> the date i have in my label'!
!AClockView class methodsFor: 'instance creation'!
open
"open an ASCII clock view and start the controller."
"AClockView open"
| topView insideView |
topView := ScheduledWindow new.
topView label: Date today printString.
topView minimumSize: 'XX:XX' asComposedText bounds corner + (32 @ 8). "Magic Numbers... (system and nt dependent)"
insideView := self new.
topView component: insideView.
topView open! !
ClockView subclass: #GClockView
instanceVariableNames: ''
classVariableNames: 'NumberForms '
poolDictionaries: ''
category: 'Interface-Clocks'!
GClockView comment:
'I am the view of the graphical clock - I display the date in my top component''s
label and display the time in my insides like a graphical clock.
Amended from VI2.3
Bernard Horan,
29 June 1992'!
!GClockView methodsFor: 'displaying'!
displayFaceOn: aGraphicsContext
"generate the background face form"
| radius center extent |
center := self bounds center.
extent := self bounds extent.
radius := extent // 2 - 12.
1 to: 12
do:
[:number |
| degree direction form |
degree := number - 3 * 30.
direction := degree degreesToRadians cos @ degree degreesToRadians sin.
form := NumberForms at: number.
form displayOn: aGraphicsContext at: center + 1 + (direction * radius) - (form bounds center).
aGraphicsContext displayRectangle: (center + (direction * (radius - 11)) extent: 2 @ 2)]!
displayHandsOn: aGraphicsContext
"display the hands of the clock. This is where the fancy stuff is..."
| x y radius center extent time hour minute |
extent := self bounds extent.
center := self bounds center.
radius := extent // 2 - 20.
time := Time now.
minute := time minutes.
hour := time hours * 5 + (minute / 12) asFloat.
x := (hour * 6 - 90) degreesToRadians cos.
y := (hour * 6 - 90) degreesToRadians sin.
aGraphicsContext lineWidth: 4.
aGraphicsContext displayLineFrom: center + (x @ y * radius // 2) to: center.
aGraphicsContext lineWidth: 2.
x := (minute * 6 - 90) degreesToRadians cos.
y := (minute * 6 - 90) degreesToRadians sin.
aGraphicsContext displayLineFrom: center + (x @ y * (radius - 8)) to: center!
displayTimeOn: aGraphicsContext
"do the updating of the view"
self displayFaceOn: aGraphicsContext.
self displayHandsOn: aGraphicsContext! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
GClockView class
instanceVariableNames: ''!
GClockView class comment:
'I am the view of the graphical clock - I hold the date in my label tab and lay the time in my insides like a graphical clock.
I am not constrained to being square.
My instance variables are:
cacheForm <Form> the bitmap of the numbers for the face of the clock,
cacheBox <rectangle> the box (i.e., self insetDisplayBox) that the face lives in,
myProject <project> the project i''m open in and,
date <date> the date i have in my label'!
!GClockView class methodsFor: 'instance creation'!
open
"open a new GClockView by executing the following comment"
"GClockView open"
| topView insideView |
topView := ScheduledWindow new.
topView label: Date today printString.
topView minimumSize: 100 @ 100.
insideView := self new.
topView component: insideView.
topView open! !
!GClockView class methodsFor: 'class initialization'!
initialize
"initialize the class constants"
"GClockView initialize"
NumberForms := Array new: 12.
1 to: 12
do:
[:number |
| text |
text := number printString asText allBold asComposedText.
NumberForms at: number put: text]! !
ControllerWithMenu subclass: #ClockController
instanceVariableNames: 'clockProcess '
classVariableNames: ''
poolDictionaries: ''
category: 'Interface-Clocks'!
ClockController comment:
'I am the controller for clock views. I set up the process that updates the ck every minute.'!
!ClockController methodsFor: 'initialize-release'!
initialize
"start the process to update the clock every minute.
One might want to make this less frequent (like every 3 minutes)."
super initialize.
clockProcess :=
[[(Delay forSeconds: 60) wait.
view invalidate.
true] whileTrue]
newProcess.
clockProcess resume!
release
"stop the update process."
clockProcess terminate! !
!ClockController methodsFor: 'control activity'!
isControlActive
"am i awake?"
^super isControlActive & sensor blueButtonPressed not! !
GClockView initialize!